home *** CD-ROM | disk | FTP | other *** search
- 'Color Picking with ZBasic 5.0
- '©MacTutor 1989
- 'By Dave Kelly
-
- WINDOW OFF
- COORDINATE WINDOW
- DIM Colorbox%(3),inColor%(3),outColor%(3),Point%(2),AlertText$(4)
- DIM RGB1%(3),PaletteRect%(3)
- red&=65535
- green&=0
- blue&=0
-
- DEF MOUSE=-1
- false%=0:true%=NOT(false)
-
- GOSUB "GetColorMode"
- IF ColorMode%>256 THEN ColorMode%=256
- LONG IF ColorMode%<16
- AlertText$(1)=""
- AlertText$(2)="This Demo must be run on a"
- AlertText$(3)=" Mac ][ in 16 or 256 colors"
- AlertText$(4)=""
- CALL PARAMTEXT(AlertText$(1),AlertText$(2),AlertText$(3),AlertText$(4))
- AlertAns%=FN NOTEALERT(1,0)
- GOTO "Quit"
- END IF
-
- MENU 1,0,1,"File"
- MENU 1,1,1,"Select Color"
- MENU 1,2,1,"Quit"
- EDIT MENU 2
-
- 'Find out screen size.
- CALL GETWMGRPORT(WMgrPort&)
- PortTop=PEEK WORD(WMgrPort&+8)
- PortLeft=PEEK WORD(WMgrPort&+10)
- PortBottom=PEEK WORD(WMgrPort&+12)
- PortRight=PEEK WORD(WMgrPort&+14)
-
- WINDOW 1,"Main Window",(10,44)-(PortRight-4,PortBottom-4),5
- GET WINDOW #1, WindowPtr&
- TEXT ,,,0
- BUTTON #6,1,"Quit",(20,WINDOW(3)-50)-(85,WINDOW(3)-30),1
- BUTTON #7,1,"Pick Color",(120,WINDOW(3)-50)-(195,WINDOW(3)-30),1
- CALL SETRECT(Colorbox%(0),10,10,WINDOW(2)-10,WINDOW(3)-215)
- PICTURE ON
- LONG COLOR blue&,green&,red&
- CALL PAINTRECT(Colorbox%(0))
- COLOR=7
- CALL FRAMERECT(Colorbox%(0))
- CALL MOVETO(20,WINDOW(3)-100)
- PRINT "Red:";red&;" Green:";green&;" Blue:";blue&;SPACE$(10)
- PICTURE OFF,Pic1&
- PICTURE, Pic1&
- WINDOW PICTURE #1,Pic1&
-
- ON DIALOG GOSUB "Event"
- ON MENU GOSUB "MenuEvent"
- DIALOG ON:MENU ON
- "Loop"
- GOTO "Loop"
- DIALOG STOP:MENU STOP
-
- "MenuEvent"
- Menunumber=MENU(0)
- Menuitem=MENU(1)
- MENU
- IF Menunumber<>1 THEN RETURN
- SELECT Menuitem
- CASE 1
- GOSUB "ColorPick"
- CASE 2
- GOSUB "Quit"
- END SELECT
- RETURN
-
- "Quit"
- WINDOW PICTURE #1,0
- KILL PICTURE Pic1&
- END
-
- "ColorPick":'A Color Selection routine
- inColor%(0)=red&
- inColor%(1)=green&
- inColor%(2)=blue&
- Result=FN GETCOLOR(Point%(0),"Choose the best color!",inColor%(0),outColor%(0))
- LONG IF Result<>0
- red&=outColor%(0)
- green&=outColor%(1)
- blue&=outColor%(2)
- IF red&<0 THEN red&=65536+red&
- IF green&<0 THEN green&=65536+green&
- IF blue&<0 THEN blue&=65536+blue&
- PICTURE ON
- LONG COLOR blue&,green&,red&
- CALL SETRECT(Colorbox%(0),10,10,WINDOW(2)-10,WINDOW(3)-215)
- CALL PAINTRECT(Colorbox%(0))
- COLOR=7
- CALL FRAMERECT(Colorbox%(0))
- CALL MOVETO(20,WINDOW(3)-100)
- PRINT "Red:";red&;" Green:";green&;" Blue:";blue&;SPACE$(10)
- PICTURE OFF,Pic1&
- PICTURE, Pic1&
- WINDOW PICTURE #1,Pic1&
- END IF
- RETURN
-
- "Event"
- D=DIALOG(0)
- SELECT D
- CASE 1
- GOSUB "ButtonEvent"
- CASE 4
- GOSUB "Quit":'if close box selected
- END SELECT
- RETURN
-
- "ButtonEvent"
- Buttonpressed=DIALOG(1)
- IF Buttonpressed=6 THEN "Quit"
- IF Buttonpressed=7 THEN "ColorPick"
- RETURN
-
- REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- REM
- "GetColorMode" 'With thanks to Zedcor and Bob Andrus
- REM
- REM SUBROUTINE TO GET THE B&W/COLOR MODE
- REM
- REM ROM85=&H028E
- REM
- REM RomTypeW& = -1 FOR 128K OR 512K
- REM RomTypeW& = 32767 FOR PLUS OR SE
- REM RomTypeW& = 16383 FOR ][
- REM
- ROM85&=&H028E
- RomTypeW&=PEEK WORD(ROM85&)
- REM
- REM TheGDevice=&H0CC8
- REM
- REM gdMode& = 128 FOR 2 B&W OR COLORS
- REM gdMode& = 129 FOR 4 B&W OR COLORS
- REM gdMode& = 130 FOR 16 B&W OR COLORS
- REM gdMode& = 131 FOR 256 B&W OR COLORS
- REM
- TheGDevice&=&H0CC8
- GDHandle&=PEEK LONG(TheGDevice&)
- GDPtr&=PEEK LONG(GDHandle&)
- gdMode&=PEEK LONG(GDPtr&+42)
- REM
- REM GET THE B&W/COLOR MODE
- REM
- IF RomTypeW&<>16383 THEN ColorMode%=2
- IF RomTypeW&<>16383 THEN RETURN
- IF gdMode&=128 THEN ColorMode%=2
- IF gdMode&=129 THEN ColorMode%=4
- IF gdMode&=130 THEN ColorMode%=16
- IF gdMode&=131 THEN ColorMode%=256
- RETURN
-
-